package com.wxg.demo.controller;

import com.alibaba.fastjson.JSON;
import com.wxg.demo.csdn1.model.User;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
public class CommonController {

    @PostMapping("/common/user/add")
    @ResponseBody
    public String userAdd(@RequestBody User user){
        System.out.println(user);
        return JSON.toJSONString(user);
    }

    @PostMapping("/common/user/add2")
    @ResponseBody
    public String userAdd(@RequestParam("userId") Integer userId,
                          @RequestParam("userName") String userName,
                          @RequestParam("userPass") String userPass){
        System.out.println(userId);
        System.out.println(userName);
        System.out.println(userPass);

        User user = new User();
        user.setUserId(userId);
        user.setUserName(userName);
        user.setUserPass(userPass);

        return JSON.toJSONString(user);
    }

}
